let page = 1,limit = 10;

$(".left-ul").find('li').click(function(){

  $(this).addClass('contentActive').siblings('li').removeClass('contentActive')
  $('.contentList').eq($(this).index()).removeClass('hide').siblings('.contentList').addClass('hide')

  $("#newtle").html($(this).html())
  page = 1;
  announcement($(this).attr('data-tis'))

})

$(".tap").find('p').click(function(){

  $(this).addClass('active').siblings('p').removeClass('active')
  $('.currBox').find('.curr').eq($(this).index()).removeClass('hide').siblings('.curr').addClass('hide')

})

// 回到顶部
$(".returnTop").click(function () {

  $("html,body").animate({
    scrollTop: '0px',
  }, 300);

  })

// 文章详情
let AjaxUrl = 'https://jzmy.jz1x.com/';
if( $(".articleInfo").length ){
  let id = location.href.split('?')[1].split('=')[1];
  $.get(AjaxUrl+'jinZhiIndex/articleDetails',
    {
      id:id
    },
    function(data){
      if( data.code == 0 ){
        let response = data.data;
        $(".loadinglast").hide();
        $("#title").html(response.title);
        $("#time").html('发布时间：'+response.checkerDate);
        $("#show").html('浏览：'+response.accessNumber+'次');
        $("#mydiv").html(response.contents)
      }
    }
  )
}

if( $(".contentList").length ){
  announcement('通知公告');
}
// 通知公告
function announcement(ev){
  
  $.get(AjaxUrl + 'jinZhiIndex/indexArticle', {
      number: 10,
      current: page,
      secondColumn: ev
    },
    function (data) {
      let str = ``;
      if( ev == '政策信息' ){
        str = `
          <div class="contentTle">
            <p class="releTle">标题</p>
            <p class="release">发布日期</p>
          </div>
        `;
      }
      data.data.indexList.forEach(function (v) {
        if( ev != '政策信息' ){
          str += `
                <div class="contentArticle">
                  <a href="articleInfo.html?id=${v.id}">
                    
                    <div class="release">
                      <img src="${v.thumbnail ? v.thumbnail : './image/big.png'}" alt="">
                    </div>
                    
                    <div class="releTle">
                      <p class="headline">${v.title}</p>
                      <div class="subject" style="position:relative">${getSimpleText(v.contents)}</div>
                    </div>
                    
                  </a>
                </div>
              `
        }else{
          str += `
            <div class="contentLink">
              <a href="articleInfo.html?id=${v.id}">
                <p class="releTle">${v.title}</p>
                <div class="release" style="position:relative">${getSimpleText(v.checkerDate)}</div>
              </a>
            </div>
          `
        }
      })

      $(".contentList").html(str);
      putInfo(data)

    }
  )
}

function getSimpleText(html) {
  const re1 = new RegExp("<.+?>", "g"); // 匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
  const arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"', 'ldquo': '“', 'mdash': '—', "rdquo": '”' };
  return html.replace(re1, '').replace(/&(lt|gt|nbsp|amp|quot|ldquo|mdash|rdquo);/ig, function (all, t) {
    return arrEntities[t];
  });
}

function putInfo(data){

  // 分页
  layui.use(['laypage'], function () {
    var laypage = layui.laypage;

    //自定义样式
    laypage.render({
      elem: 'content-page', //容器ID
      count: data.data.indexListCount, //共有多少条数据
      limit: limit, //每页显示的数据
      curr: page,
      theme: '#FF73AA',
      layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
      jump: function(obj,first){
        page = obj.curr
        limit = obj.limit
        if( !first ){
          announcement($(".contentActive").attr('data-tis'));
        }
      }, //回调函数，用于发生其他改变
      first: '首页',
      last: '尾页',
    })
  })

}


